package com.example.dllo.moondog.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import com.easemob.chat.EMChat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/1.
 */
public class BaseApplication extends Application {
    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;

        EMChat.getInstance().init(getApplicationContext());
        EMChat.getInstance().setDebugMode(true);  //在做打包混淆时，要关闭debug模式，避免消耗不必要的资源

    }

    //用于存放我们所有activity的数组
    public static List<Activity> activities;
    //向集合中添加一个activity
    public static void addActivity(Activity activity) {
        if (activities == null) {
    //如果集合为空 则初始化
            activities = new ArrayList<>();
        }
    //将activity加入到集合中
        activities.add(activity);
    }

    //结束掉所有的Activity
    public static void finishAll() {
    //循环集合, 将所有的activity finish
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }

    public static void removeActivity(Activity activity){
    //移除已经销毁的Activity
        activities.remove(activity);
    }

    public static Context getContext() {
        return context;
    }
}
